package com.longteng.diamond.util;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by taki
 * DATE : 2018/9/9 0009
 * TIME : 22:58
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:165157905@qq.com">taki</a>
 */
@Component
public class ReplaceUtil {
    /**
     * 移除 空格、\r、\n
     *
     * @param value
     * @return
     */
    public String remove(String value){
        byte[] bytes =value.getBytes();
        List<Byte> list=new ArrayList<Byte>();
        /**
         * 过滤空格、\r、\n
         * **/
        for(byte b:bytes){
            if(b !=32 && b!=10 && b!=13){
                list.add(b);
            }
        }
        byte[] bytes1=new byte[list.size()];
        final int[] i = {0};
        list.forEach(item->{
            bytes1[i[0]]=item;
            i[0]++;
        });
        return new String(bytes1);
    }
    /**
     * 替换特殊字符
     *
     * @param value
     * @return
     */
    public String replace(String value){
        value =value.replace("<","&lt;").replace(">","&gt;");
        return value;
    }
}
